package huas.ant.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import huas.ant.common.PageResult;
import huas.ant.entity.Equipment;
import huas.ant.mapper.EquipmentMapper;
import huas.ant.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    private EquipmentMapper equipmentMapper;
    /**
     * 分页列表查询
     */
    @Override
    public PageResult page(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);

        Page<Equipment> p = equipmentMapper.page();

        return new PageResult(p.getTotal(),p.getResult());
    }
    /**
     * 添加设备
     */
    @Override
    @Transactional
    public void insert(Equipment equipment) {
        equipmentMapper.reset();
        equipmentMapper.insert(equipment);
    }
    /**
     * 根据设备D查询设备信息
     */
    @Override
    public Equipment findById(Integer id) {
        Equipment equipment = equipmentMapper.findById(id);
        return equipment;
    }
    /**
     * 修改设备
     */
    @Override
    public void update(Equipment equipment) {
        equipmentMapper.update(equipment);
    }
    /**
     * 删除设备
     */
    @Override
    public void delete(Integer id) {
        equipmentMapper.delete(id);
    }
}
